import gtk, gobject
import os
import conf
	
class Mime:
	
	def return_folder_mime(self): pass
	def return_mime(self, file): pass
	
class Gnome(Mime):
	
	def return_folder_mime(self):
		type = "stock_folder"
		return type

	def return_mime(self, file):
		ext = os.path.splitext(file)[1]
		if ext == ".txt": 
			type = "gnome-mime-text"
		elif ext == ".sh":
			type = "gnome-mime-application-x-shellscript"
		elif ext == ".py":
			type = "gnome-mime-text-x-python"
		elif ext == ".pyc":
			type = "gnome-mime-application-x-python-bytecode"
		elif ext == ".php":
			type = "gnome-mime-application-x-php"
		elif ext == ".html":
			type = "gnome-mime-text-html"
		elif ext == ".zip" or ext == ".rar" or ext == ".bz2" or ext == ".gz":
			type = "gnome-mime-application-x-compress"
		elif ext == ".pdf":
			type = "gnome-mime-application-pdf"
		elif ext == ".doc" or ext == ".odt":
			type = "gnome-mime-application-vnd.oasis.opendocument.text"
		elif ext == ".png" or ext == ".jpg" or ext == ".gif" or ext == ".jpeg":
			type = "image-x-generic"
		elif ext == ".mp3" or ext == ".ogg":
			type = "audio-x-generic"
		elif ext == ".wmv" or ext == ".mpg" or ext == ".avi" or ext == ".mov":
			type = "video-x-generic"
		elif ext == ".exe" or ext == ".msi":
			type = "gnome-mime-application-x-ms-dos-executable"
		else: 
			type ="unknown"
		return type
	
class notGnome(Mime):
	
	def __init__(self, size):
  		try:
  			gtk.icon_theme_add_builtin_icon("folder", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/folder.png'))
  			gtk.icon_theme_add_builtin_icon("application-x-executable", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/application-x-executable.png'))
  			gtk.icon_theme_add_builtin_icon("text-x-generic", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/text-x-generic.png'))
  			gtk.icon_theme_add_builtin_icon("text-x-script", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/text-x-script.png'))
  			gtk.icon_theme_add_builtin_icon("text-html", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/text-html.png'))
  			gtk.icon_theme_add_builtin_icon("image-x-generic", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/image-x-generic.png'))
  			gtk.icon_theme_add_builtin_icon("package-x-generic", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/package-x-generic.png'))
  			gtk.icon_theme_add_builtin_icon("image-x-generic", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/image-x-generic.png'))
  			gtk.icon_theme_add_builtin_icon("x-office-document", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/x-office-document.png'))
  			gtk.icon_theme_add_builtin_icon("video-x-generic", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/video-x-generic.png'))
  			gtk.icon_theme_add_builtin_icon("audio-x-generic", size, gtk.gdk.pixbuf_new_from_file(conf.DATA_DIR+'/img/icons/audio-x-generic.png'))
 
  		except gobject.GError, exc:
  			print "can't load icon", exc

	def return_folder_mime(self):
		type = "folder"
		return type

	def return_mime(self, file):
		ext = os.path.splitext(file)[1]
		if ext == ".txt": 
			type = "text-x-generic"
		elif ext == ".sh" or ext == ".py" or ext == ".pyc" or ext == ".php":
			type = "text-x-script"
		elif ext == ".html":
			type = "text-html"
		elif ext == ".zip" or ext == ".rar" or ext == ".bz2" or ext == ".gz":
			type = "package-x-generic"
		elif ext == ".doc" or ext == ".odt" or ext == ".pdf":
			type = "x-office-document"
		elif ext == ".png" or ext == ".jpg" or ext == ".gif" or ext == ".jpeg":
			type = "image-x-generic"
		elif ext == ".mp3" or ext == ".ogg":
			type = "audio-x-generic"
		elif ext == ".wmv" or ext == ".mpg" or ext == ".avi" or ext == ".mov":
			type = "video-x-generic"
		elif ext == ".exe" or ext == ".msi" or ext == ".bin":
			type = "application-x-executable"
		else: 
			type ="text-x-generic"
		return type